package ModelLayer;

import java.util.ArrayList;
/**
 * 
 * 
 * @author (Brian, Jesper, Jesper og  Hoang) 
 * @version (a version number or a date)
 */
public class OrderContainer
{
    private ArrayList<DelOrdre> ordre;
    public static OrderContainer instance;
  
    private OrderContainer()
    {
        ordre = new ArrayList<DelOrdre>();
    }
    
    //Singleton
    public static OrderContainer getOrderContainer()
    {
        if(instance == null)
        {
            instance = new OrderContainer();
        }
        
        return instance;
    }
    
    //Constructor
    public void addOrdre(DelOrdre _ordre)
    {
        ordre.add(_ordre);
    }
    
    //ID søge funktion
    public DelOrdre searchById(int _id)
    {
        DelOrdre retOrdre = null;
        int index = 0;
        boolean found = false;
        
        while(index < ordre.size() && !found)
        {
            DelOrdre currOrdre = ordre.get(index);
            if(currOrdre.getId() == _id)
            {
                retOrdre = currOrdre;
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        return retOrdre;
    }
    
    //Metode til at liste alle ordrene
    public ArrayList<DelOrdre> getAllOrdre()
    {
        return ordre;
    }
    
    //Metode til at slette en order
    public void deleteOrdre(DelOrdre _ordre)
    {
        ordre.remove(_ordre);
    }
}
